﻿Imports FinanceiroDAL.ModuloConexao
Public Class RelCaixa
#Region "Itens"
    Private Sub RBAberto_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBAberto.CheckedChanged
        If RBAberto.Checked Then
            gerarelatrio("Caixa Aberto", "{vw_FinCaixa.sta_codigo}=4") 'caixas abertos
        End If
    End Sub

    Private Sub RBFechados_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBFechados.CheckedChanged
        If RBFechados.Checked Then
            gerarelatrio("Caixa Fechado", "{vw_FinCaixa.sta_codigo}=6")
        End If
    End Sub

    Private Sub rbtodos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbtodos.CheckedChanged
        If (rbtodos.Checked) Then
            gerarelatrio("Relação de Caixa - Geral", "")
        End If

    End Sub
    Private Sub RBDia_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBDia.CheckedChanged
        If RBDia.Checked Then
            gerarelatrio("Caixa do Dia", "{vw_FinCaixa.cai_dtabertura}= DATETIME('" & Date.Now.Date.ToString("yyyy-MM-dd") & " 23:59:59')")
        End If
    End Sub
#End Region
#Region "Relatorio"
    Public Sub gerarelatrio(titulo As String, formula As String)
        Try
            Dim frm As New RelatoriosfinFRM
            Dim rpt As New CaixaREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frm.CrystalReportViewer2.ShowGroupTreeButton = False
                frm.CrystalReportViewer2.ReportSource = rpt
                frm.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frm.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally
        End Try
    End Sub
#End Region
#Region "Relatorio2"
    Public Sub gerarelatrio2(titulo As String, formula As String)
        Try
            Dim frm As New RelatoriosfinFRM
            Dim rpt As New CaixaDetalhadoREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frm.CrystalReportViewer2.ShowGroupTreeButton = False
                frm.CrystalReportViewer2.ReportSource = rpt
                frm.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frm.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally
        End Try
    End Sub
#End Region
End Class